package cn.colat.micse.common.config;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.same.SaSameUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

@Configuration
public class FeignClientInterceptor implements RequestInterceptor {

    /**
     * 访问子服务 为请求追加 Same-Token 参数
     */
    @Override
    public void apply(RequestTemplate template) {
        String token = SaHolder.getRequest().getHeader(SaSameUtil.SAME_TOKEN);
        if (StringUtils.hasText(token)) {
            template.header(SaSameUtil.SAME_TOKEN, token);
        }
    }
}